<%--
  Created by IntelliJ IDEA.
  User: lin
  Date: 2019/1/4
  Time: 9:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>用户登录</title>
    <%
        pageContext.setAttribute("APP_PATH", request.getContextPath());
    %>
    <script type="text/javascript"
            src="${APP_PATH }/static/js/jquery-1.12.4.min.js"></script>
    <link
            href="${APP_PATH }/static/bootstrap-3.3.7-dist/css/bootstrap.min.css"
            rel="stylesheet"/>
    <script
            src="${APP_PATH }/static/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
    <style>
        body{
            margin-left:auto;
            margin-right:auto;
            margin-TOP:100PX;
            width:20em;
        }
    </style>
</head>
<body>
<div class="container-fluid">
<form method="post">

    <div class="form-group" >
        <div align="center">
        <h3><strong>江大学生信息管理</strong></h3>
        </div>
        <label for="login_name">用户名</label>
        <input type="text" class="form-control" id="login_name" name="loginName" placeholder="用户名">
        <span class="help-block"></span>
    </div>
    <div class="form-group">
        <label for="password" >密码</label>
        <input type="password" class="form-control" id="password" name="password" placeholder="密码">
    </div>


</form>
    <div align="center">

        <button type="submit" class="btn btn-primary btn-lg btn-block" id="login_btn" >登录</button>
    </div>

    <script type="text/javascript">

        $("#login_btn").click(function () {
            $.ajax({
                url:"${APP_PATH}/login.do",
                type:"POST",
                data:{"loginName":$("#login_name").val(),"password":$("#password").val()},
                success:function (result) {
                    if (result.code == 100) {
                        location.href="${APP_PATH}/success.jsp"
                    }else {
                        show_validate_msg("#login_name","error","用户名或密码错误");
                    }
                }
            });
        });

        //显示校验结果的提示信息
        function show_validate_msg(ele,status,msg){
            //清除当前元素的校验状态
            $(ele).parent().removeClass("has-success has-error");
            //$(ele).next("span").text("");
            if("success"==status){
                $(ele).parent().addClass("has-success");
                $(ele).next("span").text(msg);
            }else if("error" == status){
                $(ele).parent().addClass("has-error");
                $(ele).next("span").text(msg);
            }
        }


    </script>

</div>
</body>
</html>
